package me.CSmethod.demo;

import java.sql.SQLOutput;
import java.util.Random;
import java.util.Scanner;

public class Text10 {
    public static void main(String[] args) {

        //1.生成中奖号码
        int a[] = creatNumber();

        //2.用户输入号码（红球+蓝球）
        int userInput[] = userIputnumber();

        //3.判断用户中奖情况
        int redCount = 0;
        int blueCount = 0;

        //判断红球
        for (int i = 0; i < userInput.length - 1; i++) {
            for (int j = 0; j < a.length - 1; j++) {
                if (userInput[i] == a[j]) {
                    redCount++;
                    //如果找到了，那么后面的数字就没必要继续比较了
                    //所以直接跳出当前循环，进入下一个循环
                    break;
                }
            }
        }

        //判断蓝球
        if (userInput[userInput.length - 1] == a[a.length - 1]) {
            blueCount++;
        }

        //判断中奖情况 也可用switch语句
        if (redCount == 6 && blueCount == 1) {
            System.out.println("恭喜你，中奖1000万");
        } else if (redCount == 6 && blueCount == 0) {
            System.out.println("恭喜你，中奖500万");
        } else if (redCount == 5 && blueCount == 1) {
            System.out.println("恭喜你，中奖3000");
        } else if ((redCount == 5 && blueCount == 0) || (redCount == 4 && blueCount == 1)) {
            System.out.println("恭喜你，中奖200");
        } else if ((redCount == 4 && blueCount == 0) || (redCount == 3 && blueCount == 1)) {
            System.out.println("恭喜你，中奖10");
        } else if ((redCount == 2 && blueCount == 1) || (redCount == 1 && blueCount == 1) || (redCount == 0 && blueCount == 1)) {
            System.out.println("恭喜你，中奖5");
        } else {
            System.out.println("谢谢参与，谢谢惠顾");
        }
    }

    public static int[] userIputnumber() {

        //1.创建数组用于添加用户购买的彩票号码
        //6个红球1个篮球  数组长度：7
        int a[] = new int[7];

        //2.利用键盘录入让用户输入
        Scanner sc = new Scanner(System.in);
        //输入红球号码
        for (int i = 0; i < a.length - 1; ) {
            System.out.println("请输入第" + (i + 1) + "个红球号码");
            int redNumber = sc.nextInt();

            //redNumber 在1~33 唯一不重复
            if (redNumber >= 1 && redNumber <= 33) {
                boolean flag = check(a, redNumber);
                if (flag) {
                    a[i] = redNumber;
                    i++;
                } else {
                    System.out.println("当前红球号码已存在,请重新输入");
                }
            } else {
                System.out.println("当前红球号码超出范围");
            }
        }
        System.out.println("请输入蓝球号码");

        //1~16
        while (true) {
            int blueNumber = sc.nextInt();
            if (blueNumber >= 1 && blueNumber <= 16) {
                a[a.length - 1] = blueNumber;
                break;
            } else {
                System.out.println("当前蓝球号码超出范围");
            }
        }
        return a;
    }

    public static int[] creatNumber() {

        //1.创建数组用于添加中奖号码
        //6个红球1个篮球  数组长度：7
        int a[] = new int[7];

        //2.随机生成红色号码
        Random r = new Random();
        for (int i = 0; i < a.length - 1; ) {
            int redNumber = r.nextInt(33) + 1;
            boolean flag = check(a, redNumber);
            if (flag) {
                a[i] = redNumber;
                i++;
            }
        }

        //3.随机生成蓝色号码
        int blueNumber = r.nextInt(16) + 1;
        a[a.length - 1] = blueNumber;
        return a;
    }

    //用于判断数字在数组中是否存在
    public static boolean check(int a[], int number) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] == number) {
                return false;
            }
        }
        return true;
    }
}
